package net.yebaihe.wc;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class AllSubway extends StateMachine{

	private SQLiteDatabase listdb;

	@Override
	protected String getTopbarTitle() {
		return "所有地铁";
	}

	@Override
	protected void prepareClient(View client) {
		listdb=MyHelper.get(this).getReadableDatabase();
		ListView lstZone=(ListView) client.findViewById(R.id.lstzone);
		if (listdb!=null){
			Cursor c=listdb.rawQuery("select * from subway where city='"+getWCAppContext().city+"'", null);
			startManagingCursor(c);
			ListAdapter listAdapter = new SimpleCursorAdapter(this, R.layout.itemzone,
					c,
					new String[]{"name"},
					new int[]{R.id.txtname});
			lstZone.setAdapter(listAdapter);
			lstZone.setOnItemClickListener(new OnItemClickListener(){
				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					getWCAppContext().otherRestaurantSql="and _id in (select distinct restaurant from subway_restaurant where subway="+arg3+")";
					changeToActivity(NearBy.class);
				}
			});
		}
	}

	@Override
	protected int getLayoutRes() {
		return R.layout.allzone;
	}

	@Override
	public void onDestroy(){
		listdb.close();
		super.onDestroy();
	}

}
